{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from glob import glob\n",
    "from IPython.display import Image as display\n",
    "import numpy as np\n",
    "from PIL import Image\n",
    "import time\n",
    "paths = glob('./test/*.*')\n",
    "paths"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## pytorch crnn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "im = Image.open(paths[-2])\n",
    "img = np.array(im.convert('RGB'))\n",
    "t = time.time()\n",
    "result,img,angle = model.model(img,model='crnn', detectAngle=True) ## if model == crnn ,you should install pytorch\n",
    "print \"It takes time:{}s\".format(time.time()-t)\n",
    "print \"---------------------------------------\"\n",
    "print \"图像的文字朝向为:{}度\\n\".format(angle),\"识别结果:\\n\"\n",
    "\n",
    "for key in result:\n",
    "    print result[key][1]\n",
    "    \n",
    "Image.fromarray(img)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## keras crnn "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "im = Image.open(paths[-2])\n",
    "img = np.array(im.convert('RGB'))\n",
    "t = time.time()\n",
    "result,img,angle = model.model(img,model='keras',detectAngle=True) ##if model == keras ,you should install keras\n",
    "print \"It takes time:{}s\".format(time.time()-t)\n",
    "print \"---------------------------------------\"\n",
    "print \"图像的文字朝向为:{}度\\n\".format(angle),\"识别结果:\\n\"\n",
    "for key in result:\n",
    "    print result[key][1]\n",
    "Image.fromarray(img)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
